package com.eastfair.auth.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 业务日志记录
 * </p>
 *
 * @author ligang
 * @date 2023-02-13
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "HttpMethod", description = "请求类型#HttpMethod{GET:GET请求;POST:POST请求;PUT:PUT请求;DELETE:DELETE请求;PATCH:PATCH请求;TRACE:TRACE请求;HEAD:HEAD请求;OPTIONS:OPTIONS请求;-枚举")
public enum HttpMethod implements BaseEnum {

    /**
     * GET="GET请求"
     */
    GET("GET请求"),
    /**
     * POST="POST请求"
     */
    POST("POST请求"),
    /**
     * PUT="PUT请求"
     */
    PUT("PUT请求"),
    /**
     * DELETE="DELETE请求"
     */
    DELETE("DELETE请求"),
    /**
     * PATCH="PATCH请求"
     */
    PATCH("PATCH请求"),
    /**
     * TRACE="TRACE请求"
     */
    TRACE("TRACE请求"),
    /**
     * HEAD="HEAD请求"
     */
    HEAD("HEAD请求"),
    /**
     * OPTIONS="OPTIONS请求"
     */
    OPTIONS("OPTIONS请求"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static HttpMethod match(String val, HttpMethod def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static HttpMethod get(String val) {
        return match(val, null);
    }

    public boolean eq(HttpMethod val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "GET,POST,PUT,DELETE,PATCH,TRACE,HEAD,OPTIONS", example = "GET")
    public String getCode() {
        return this.name();
    }

}
